home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TDE.ARJ / TDEPHONE.CPP < prev    next >
C/C++ Source or Header  |  1992-07-14  |  6KB  |  206 lines

  1. /***************************************************************************
  2.  
  3.  FILENAME - TDEPHONE.CPP: classes TDEPhone, TDEZipCode, TDEState
  4.  -----------------------
  5.  
  6.  Class TDataEntry v1.0 - 07/14/92
  7.  --------------------------------
  8.  
  9.  ----------------------------------------------------------------------------
  10.  Author: Jeff Penrose * JDP Custom Software * (818) 344-7303 * CIS 71043,3727
  11.  ----------------------------------------------------------------------------
  12.  
  13.  A data entry class for Borland's Turbo Vision, derived from TInputLine.
  14.  
  15.  Copyright Notice
  16.  ================
  17.   As this material is ultimately derived from Borland source files, any of
  18.  their copyrights which MAY apply DO apply.
  19.   From the author's standpoint, you may use this material freely and,
  20.  hopefully, post any comments/corrections/enhancements to me at the above-
  21.  noted addresses.  I do ask that you not distribute this material except as
  22.  originally received, including all source/documentation files in their
  23.  original form.
  24.   If you DO modify or enhance any of this code, please send any such changes
  25.  to me for incorporation into a future version.  Any such enhancements will
  26.  be DONATED, without expectation of compensation or incorporation into
  27.  future versions.  Again, if you distribute this code, please do so in its
  28.  original, unmodified form including all source files and documentation.
  29.  
  30.  Source files included
  31.  =====================
  32.  TDE     .DOC: This documentation.
  33.  TDE     .MAN: How to use TDataEntry in your dialog objects
  34.  TDE     .H  : header file containing class declarations for classes
  35.  TDEFLAGS.H  :   "     "      "       flags and command definitions
  36.  TDE     .CPP: Class TDataEntry
  37.  TDEDATE .CPP: Class TDEDate
  38.  TDEPHONE.CPP: Classes TDEPhone, TDEZipCode, TDEState
  39.  TDENUMS .CPP: Class TDEInteger
  40.  TDECLUST.CPP: Non-TDataEntry classes TDEButton, TDERadioButtons, TDECheckBoxes
  41.  TDEINPLI.CPP: Non-TDataEntry class TDEInputLine
  42.  TDELIB  .PRJ: Project for building library TDELIB.LIB
  43.  TDEDEMO .CPP: Demo program
  44.  TDEDEMO .PRJ: Project for building TDEDEMO.EXE
  45.  
  46. ***************************************************************************/
  47. #define   Uses_TDEPhone
  48. #define   Uses_TDEZipCode
  49. #define   Uses_TDEState
  50. #include  <tde.h>
  51. #include  <stdlib.h>  // atof(), atol()
  52. #include  <string.h>  // strlen(), strcpy(), strstr()
  53.  
  54. #ifndef ulong
  55.   typedef unsigned long  ulong;
  56. #endif
  57.  
  58. //--------------------------------------------------------------------------
  59. //
  60. // **** TDEPhone::valid()
  61. //
  62. //--------------------------------------------------------------------------
  63. Boolean TDEPhone::valid(ushort cmd)
  64. {
  65.   if ( cmd == cmValid && !(maxLen == 7 || maxLen == 10) )
  66.     return False;
  67.  
  68.   return TDataEntry::valid(cmd);
  69. }
  70.  
  71. //--------------------------------------------------------------------------
  72. //
  73. // **** TDEPhone::validData()
  74. //
  75. //--------------------------------------------------------------------------
  76. Boolean TDEPhone::validData( const char *, const char * )
  77. {
  78.   float    val;
  79.   int      len = strlen(data);
  80.   Boolean  dataOK = True;
  81.   char     *msg = "\003Invalid phone number!";
  82.  
  83.   if ( !TDataEntry::validData(msg, "\003Phone number is required!") )
  84.     return False;
  85.  
  86.   if ( len && !(len == 7 || len == 10) )
  87.     dataOK = False;
  88.  
  89.   if ( dataOK && len )
  90.   {
  91.     val = atof(data);
  92.     if ( len == 7 && (val < 1000000.0 || val > 9999999.0) )
  93.       dataOK = False;
  94.     else if ( len == 10 && (val < 1000000000.0 || val > 9999999999.0) )
  95.       dataOK = False;
  96.   }
  97.  
  98.   if ( !dataOK )
  99.   {
  100.     if ( (globalMode & tdgBeepEnable) != 0 )  cout << (char) 7;
  101.     messageBox(msg, mfError | mfOKButton);
  102.     select();
  103.   }
  104.   return dataOK;
  105. }
  106.  
  107. //--------------------------------------------------------------------------
  108. //
  109. // **** TDEZipCode::valid()
  110. //
  111. //--------------------------------------------------------------------------
  112. Boolean TDEZipCode::valid(ushort cmd)
  113. {
  114.   if ( cmd == cmValid && !(maxLen == 5 || maxLen == 9) )
  115.     return False;
  116.  
  117.   return TDataEntry::valid(cmd);
  118. }
  119.  
  120. //--------------------------------------------------------------------------
  121. //
  122. // **** TDEZipCode::validData()
  123. //
  124. //--------------------------------------------------------------------------
  125. Boolean TDEZipCode::validData( const char *, const char * )
  126. {
  127.   ulong   val;
  128.   int     len = strlen(data);
  129.   Boolean dataOK = True;
  130.   char    *msg = "\003Invalid zip code!";
  131.  
  132.  
  133.   if ( !TDataEntry::validData(msg, "\003Zip code is required!") )
  134.     return False;
  135.  
  136.   if ( len && !(len == 5 || len == 9) )
  137.     dataOK = False;
  138.  
  139.   if ( dataOK && len )
  140.   {
  141.     val = atol(data);
  142.     if ( len == 5 && (val < 10000UL || val > 99999UL) )
  143.       dataOK = False;
  144.     else if ( len == 9 && (val < 100000000UL || val > 999999999UL) )
  145.       dataOK = False;
  146.   }
  147.  
  148.   if ( !dataOK )
  149.   {
  150.     if ( (globalMode & tdgBeepEnable) != 0 )  cout << (char) 7;
  151.     messageBox(msg, mfError | mfOKButton);
  152.     select();
  153.   }
  154.  
  155.   return dataOK;
  156. }
  157.  
  158. //--------------------------------------------------------------------------
  159. //
  160. // **** TDEState::valid()
  161. //
  162. //--------------------------------------------------------------------------
  163. Boolean TDEState::valid(ushort cmd)
  164. {
  165.   if ( cmd == cmValid && maxLen != 2 )
  166.     return False;
  167.  
  168.   return TDataEntry::valid(cmd);
  169. }
  170.  
  171. //--------------------------------------------------------------------------
  172. //
  173. // **** TDEState::validData()
  174. //
  175. //--------------------------------------------------------------------------
  176. static char *states =
  177.   "AL,AK,AZ,AR,CA,CO,CT,DC,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,"
  178.   "MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,"
  179.   "WV,WI,WY";
  180.  
  181. Boolean TDEState::validData( const char *, const char *)
  182. {
  183.   int     len = strlen(data);
  184.   Boolean dataOK = True;
  185.   char    *msg   = "\003Invalid state!";
  186.  
  187.  
  188.   if ( !TDataEntry::validData(msg, "\003State is required!") )
  189.     return False;
  190.  
  191.   if ( len && len != 2 )
  192.     dataOK = False;
  193.  
  194.   if ( dataOK && len && !( strstr(states, data) ) )
  195.     dataOK = False;
  196.  
  197.   if ( !dataOK )
  198.   {
  199.     if ( (globalMode & tdgBeepEnable) != 0 )  cout << (char) 7;
  200.     messageBox(msg, mfError | mfOKButton);
  201.     select();
  202.   }
  203.  
  204.   return dataOK;
  205. }
  206.